home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / swap.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-02  |  2.5 KB  |  84 lines

  1. /*
  2.  
  3.     File: swap.c
  4.  
  5.     Copyright (C) 1998-2004 Christophe GRENIER <grenier@cgsecurity.org>
  6.   
  7.     This software is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.   
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.   
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  */
  22. #include <string.h>
  23. #include "types.h"
  24. #include "common.h"
  25. #include "swap.h"
  26. #include "fnctdsk.h"
  27.  
  28. int check_Linux_SWAP(t_param_disk *disk_car,t_diskext *partition,const int debug)
  29. {
  30.   unsigned char buffer[8*SECTOR_SIZE];
  31.   if(disk_car->read(disk_car,8, &buffer, partition->lba)!=0)
  32.   { return 1; }
  33.   if(test_Linux_SWAP(disk_car,(union swap_header*)&buffer,partition,debug,0)!=0)
  34.     return 1;
  35.   return 0;
  36. }
  37.  
  38. int test_Linux_SWAP(t_param_disk *disk_car, const union swap_header *swap_header,t_diskext *partition,const int debug, const int dump_ind)
  39. {
  40.   if(memcmp(swap_header->magic.magic,"SWAP-SPACE",10)==0)
  41.   {
  42.     partition->upart_type=UP_LINSWAP;
  43.     return 0;
  44.   }
  45.   if(memcmp(swap_header->magic.magic,"SWAPSPACE2",10)==0)
  46.   {
  47.     partition->upart_type=UP_LINSWAP2;
  48.     return 0;
  49.   }
  50.   return 1;
  51. }
  52.  
  53. int recover_Linux_SWAP(t_param_disk *disk_car, const union swap_header *swap_header,t_diskext *partition,const int debug, const int dump_ind)
  54. {
  55.   if(test_Linux_SWAP(disk_car,swap_header,partition,debug,dump_ind)!=0)
  56.     return 1;
  57.   partition->part_type=(unsigned char)P_LINSWAP;
  58.   switch(partition->upart_type)
  59.   {
  60.     case UP_LINSWAP:
  61.       {
  62.     int i, j;
  63.     for(i=PAGE_SIZE-10-1;i>=0;i--)
  64.       if(swap_header->magic.reserved[i]!=(char)0)
  65.         break;
  66.     for(j=7;j>=0;j--)
  67.       if((swap_header->magic.reserved[i]&(1<<j))!=(char)0)
  68.         break;
  69.     partition->part_size=(dword)((8*i+j+1)*(PAGE_SIZE/SECTOR_SIZE));
  70.     if(debug>1)
  71.       ecrit_rapport("SWAP version %u\n",swap_header->info.version);
  72.       }
  73.       break;
  74.     case UP_LINSWAP2:
  75.       partition->part_size=(swap_header->info.last_page - 1)*(PAGE_SIZE/SECTOR_SIZE);
  76.       if(debug>1)
  77.     ecrit_rapport("SWAP2 version %u\n",swap_header->info.version);
  78.       break;
  79.     default:
  80.       return 1;
  81.   }
  82.   return 0;
  83. }
  84.